﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Data.SqlClient;
namespace DataAccess
{
    public class TruyXuatDatVe
    {
        DatVe _datve = new DatVe();

        public DatVe datve
        {
            get { return _datve; }
            set { _datve = value; }
        }
        ChiTietDatVe _chitiet = new ChiTietDatVe();

        public ChiTietDatVe chitiet
        {
            get { return _chitiet; }
            set { _chitiet = value; }
        }
        public int ThucThi()
        {
            try
            {
                DataProvider dp = new DataProvider();
                dp.KetNoi();
                string sql = "insert into DATVE(ChuyenBayDi,NgayDi,ChuyenBayVe,NgayVe,SLNgLonTK,SLTreEmTK,SLSoSinhTK,SLNgLonPT,SLTreEmPT,SLSoSinhPT,SLNgLonTG,SLTreEmTG,SLSoSinhTG,ThoiGianDatVe,LoaiVe,TrangThai,TongTien) values("+datve.MaChuyenBay+",'"+datve.NgayDi+"',"+datve.ChuyenBayVe+",'"+datve.NgayVe+"',"+datve.SLNgLonTK+","+datve.SLTreEmTK+","+datve.SLSoSinhTK+","+datve.SLNgLonPT+","+datve.SLTreEmPT+","+datve.SLSoSinhPT+","+datve.SLNgLonTG+","+datve.SLTreEmTG+","+datve.SLSoSinhTG+",'"+datve.ThoiGianDatVe+"',"+datve.LoaiVe+",'Chua Thanh Toan','"+datve.TongTien+"')";
                dp.cm = new SqlCommand(sql, dp.cn);
                if (dp.cm.ExecuteNonQuery()==1)
                {
                    string sql1 = "select MAX( MaDatVe) from DatVe";
                    int madatve = (int)dp.executeScalar(sql1);
                    string sql2 = "insert into ChiTietDatVe(MaDatVe,SoGiayToTuyThan,SoHoiVien,HoTen,SoDT,DiaChi,Email,SoCreditCard) values("+madatve+",'"+chitiet.SoGiayToTuyThan+"',"+chitiet.SoHoiVien+",N'"+chitiet.HoTen+"','"+chitiet.SoDT+"','"+chitiet.DiaChi+"','"+chitiet.Email+"','"+chitiet.SoCreditCard+"')";
                    try
                    {
                        dp.ExecuteNonQuery(sql2);
                        return madatve;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                return 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }

}
